home *** CD-ROM | disk | FTP | other *** search
- Path: morgan.cnu.edu!dlabell
- From: dlabell@pcs.cnu.edu (Daniel LaBell)
- Newsgroups: comp.lang.c++
- Subject: Re: casting a void pointer back to a function pointer
- Date: 04 Apr 1996 21:26:04 GMT
- Organization: not one of my strong points
- Message-ID: <DLABELL.96Apr4162605@sovereign.pcs.cnu.edu>
- References: <DLABELL.96Apr4021045@columbia.pcs.cnu.edu>
- NNTP-Posting-Host: sovereign.pcs.cnu.edu
- In-reply-to: dlabell@pcs.cnu.edu's message of 04 Apr 1996 07:10:45 GMT
-
- (yes, I am answering my own post.) A friend of mine checked a book,
- he had available at work, and gave me the synatax to declare a pointer
- to a type of function.
- this works:
- // Daniel LaBell
- // ~dlabell/C/test.cc
- #include <iostream.h>
- void foo1(){ cout << " foo1 " << endl; }
- void foo2(){ cout << " foo2 " << endl; }
- void foo3( int x )
- { cout << " foo3, argument = " << x << endl; }
- void do_a_foo( void (*fun)() )
- { (*fun)(); }
- void do_a_foo( int x, void (*fun) (int ) )
- { fun ( x ); }
- int main()
- {
- do_a_foo ( foo1 );
- void ( * funcP)()=foo2;
- do_a_foo (funcP);
- void ( * funcP2)(int)=foo3;
- do_a_foo ( 2, funcP2 );
- return 0;
- }
- Actually, this is wanted I wanted to do from the start, I just thought
- it wasn't possible. So, I don't really need to know the syntax for
- the cast now, but if anyone knows it, I wouldn't mind adding it to
- my bag of tricks. :)
-
-
-
- --
- Daniel LaBell
-